
====================
' This file was modified as part of an ASP.NET 2.0 Web project conversion.
' The class name was changed and the class modified to inherit from the abstract base class 
'''/ in file 'App_Code\Migrated\Stub_members_aspx_cs.cs'.
' During runtime, this allows other classes in your web application to bind and access 
' the code-behind page using the abstract base class.
' The associated content page 'members.aspx' was also modified to refer to the new class name.
' For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995 
====================
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for members.
	''' </summary>
	Public Partial Class Migrated_members
		Inherits members
		Protected lblPhotosCount As System.Web.UI.WebControls.Label
		Protected id As Integer = -1
		Protected hlRecommend As System.Web.UI.WebControls.HyperLink
		Protected memberName As String = ""
		Protected memberNameOwner As String = ""
		Protected sfriendsCount As String = ""
		Protected htPageConstants As New Hashtable()
		Private member As BO.User = Nothing

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.MEMBERS_PAGE;

			Dim usr As User = LoggedUser
			'string parentPage = Request.ServerVariables["HTTP_REFERER"];

			'if(usr == null)
			'if ( parentPage.ToLower().IndexOf(Constants.DEFAULT.ToLower()) == -1)
			'Response.Redirect(Constants.LOGIN_PAGE);

			If Request.Params("id") <> Nothing AndAlso Request.Params("id") <> "" Then
				id = Convert.ToInt32(Request.Params("id"))
			Else
				If LoggedUser <> Nothing Then
					id = LoggedUser.ID
				Else
					Common.Utils.RedirectToLoginPage(Page)
				End If
			End If

			Me.initPageTitles(Constants.MEMBERS, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			member = Users.GetUserByID(id)
			If member = Nothing Then
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End If

			If member.Status = Users.STATUS_LOCKED Then
				Throw New Exception("User " + member.Name + " has canceled his/her account.")
			End If
			' init member template
			Dim userTemplate As BO.Template = member.Template
			Me.pageTemplate.wavFile = InitWAVFileURL(member.WAVURL)
			Me.pageTemplate.bgImage = InitBGImage(member.BGImageURL)

			' NOTE : what do we do if there's no template? -> Load the default css file
			If userTemplate <> Nothing AndAlso cssFileName <> Nothing Then
				cssFileName = userTemplate.CSSFileName
				'set with DB value: cssFileName = Templates.getTemplateByID(themeID).CSSFileName;
				pageTemplate.StrStyle = Me.InitStyle(cssFileName)
			End If

			If (usr <> Nothing) AndAlso (usr.ID <> member.ID) Then
				System.Math.Max(System.Threading.Interlocked.Increment(member.TimesViewed),member.TimesViewed - 1)
				member.Save()
			End If

			memberName = member.Name
			memberNameOwner = member.Name + "'s"
			' init member photo
			Dim MemPicture As UserPicture = member.DefaultPicture
			If MemPicture <> Nothing Then
				imgMember.ImageUrl = Pictures.GetPictureLargeThumbnailSrcFullURL(MemPicture, "../")
			Else
				imgMember.ImageUrl = "../images/default_thumbnail.gif"
			End If
			imgMember.ToolTip = member.Name

			' init online status	
			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()
			If LoggedUsersList.Contains(member.ID) Then
				imgOnlineImage.ImageUrl = "../images/online_status.gif"
			Else
				imgOnlineImage.Visible = False
				'init according to the friend's online status
			End If

			'init member since date
			lblMemberSince.Text = Constants.ARR_MONTHS(member.RegistrationDate.Month - 1) + " " + member.RegistrationDate.Year
			' init last login date
			If DateTime.Compare(member.LastLoginDate, DateTime.MinValue) = 0 Then
				lblLastLoginDate.Text = member.RegistrationDate.Day + "/" + member.RegistrationDate.Month + "/" + member.RegistrationDate.Year
			Else
				lblLastLoginDate.Text = member.LastLoginDate.Day + "/" + member.LastLoginDate.Month + "/" + member.LastLoginDate.Year
				'if the user has never logged in then show registration date instead
			End If


			' init pictures count
			Dim pics As ArrayList = member.GetPictures()
			hlPhotos.Text = "<font class='main_text_opposite_bold'>" + pics.Count.ToString() + "</font>" + " Photo"
			If pics.Count <> 1 Then
				hlPhotos.Text += "s"
			End If
			hlPhotos.Text += " in Album"
			hlPhotos.NavigateUrl = "../" + Constants.VIEW_MEMBER_PHOTOS_PAGE + "?id=" + id

			' init links
			hlAddComment.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=" + member.ID
			hlAddComment2.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=" + member.ID
			hlAddComment3.NavigateUrl = "../" + Constants.FRIENDS_ADD_COMMENT + "?usr=" + member.ID
			hlSendMessage.NavigateUrl = "../" + Constants.SEND_MESSAGE + "?uid=" + member.ID
			hlAllBlog.NavigateUrl = "../" + Constants.VIEW_MEMBER_BLOG + "?id=" + member.ID
			hlSeeAllFriendsUp.NavigateUrl = "../" + Constants.SEE_ALL_FRIENDS + "?id=" + member.ID
			hlAddToFriends.NavigateUrl = "../" + Constants.ADD_FRIEND_CONFIRMATION_PAGE + "?id=" + member.ID + "&action=" + Constants.NEW_FRIENDSHIP
			hlBlockUser.NavigateUrl = "../" + Constants.BLOCK_USER + "?id=" + member.ID
			hlAddToFav.NavigateUrl = "../" + Constants.ADD_TO_FAVORITES + "?id=" + member.ID
			hlForwardToFriend.NavigateUrl = "../" + Constants.SEND_MESSAGE + "?" + Constants.FORWARD_A_FRIEND_PARAM + "=" + member.ID + "&action=" + Constants.MESSAGE_FORWARD_A_FRIEND_ACTION
			'hlRecommend.NavigateUrl = "../" + Constants.FRIENDS_LIST + "?" + Constants.RECOMMENDED_USER_PARAM + "=" + member.ID;

			If Constants.SHOW_GROUPS <> Constants.SHOW_ON Then
				tblGroups.Visible = False
			End If

			' set About Me			
			lblAboutMe.Text = Me.GetPageConstText(htPageConstants, "CONST_AboutMe_TEXT")
			lblAboutMe.Font.Bold = True
			'lblAboutMeValue.Text = "<b>Last updated: " + member.EditDate.Day + "/" + member.EditDate.Month + "/" +member.EditDate.Year + "</b> <br><br>";
			lblAboutMeValue.Text += member.AboutMe

			' set Like to Meet
			lblMeet.Text = Me.GetPageConstText(htPageConstants, "CONST_LikeToMeet_TEXT")
			lblMeet.Font.Bold = True
			lblMeetValue.Text = member.LookingFor
			If lblMeetValue.Text <> "" Then
				lblMeet.Visible = True
			Else
				lblMeet.Visible = False
			End If

			Dim isSongEntered As Boolean = False
			' set Live Music
			If member.SongURL1 <> Nothing AndAlso member.SongURL1 <> "" Then
				If member.SongURLName1 <> Nothing AndAlso member.SongURLName1 <> "" Then
					hlSongName1.Text = HttpUtility.HtmlEncode(member.SongURLName1) + "<br><br>"
				Else
					hlSongName1.Text = HttpUtility.HtmlEncode(member.SongURL1) + "<br><br>"
					'hlSongName1.Text  = getBeginning( HttpUtility.HtmlEncode( member.SongURLName1 ), Constants.NAME_MAX_VISIBLE_CHARS) + "<br><br>";
				End If

				hlSongName1.CssClass = "member_main_text"
				hlSongName1.Font.Bold = True
				hlSongName1.Attributes.Add("href", "#song")
				hlSongName1.Attributes.Add("onclick", Me.constructMusicURL(member.SongURL1))
				isSongEntered = True
			End If
			If member.SongURL2 <> "" AndAlso member.SongURL2 <> Nothing Then
				If member.SongURLName2 <> Nothing AndAlso member.SongURLName2 <> "" Then
					hlSongName2.Text = HttpUtility.HtmlEncode(member.SongURLName2) + "<br><br>"
				Else
					hlSongName2.Text = HttpUtility.HtmlEncode(member.SongURL2) + "<br><br>"
				End If

				hlSongName2.CssClass = "member_main_text"
				hlSongName2.Font.Bold = True
				hlSongName2.Attributes.Add("href", "#song")
				hlSongName2.Attributes.Add("onclick", Me.constructMusicURL(member.SongURL2))
				isSongEntered = True
			End If
			If member.SongURL3 <> "" AndAlso member.SongURL3 <> Nothing Then
				If member.SongURLName3 <> Nothing AndAlso member.SongURLName3 <> "" Then
					hlSongName3.Text = HttpUtility.HtmlEncode(member.SongURLName3)
				Else
					hlSongName3.Text = HttpUtility.HtmlEncode(member.SongURL3)
				End If

				hlSongName3.CssClass = "member_main_text"
				hlSongName3.Font.Bold = True
				hlSongName3.Attributes.Add("href", "#song")
				hlSongName3.Attributes.Add("onclick", Me.constructMusicURL(member.SongURL3))
				isSongEntered = True
			End If

			trSongs.Visible = isSongEntered

			' init AdminLinks

			If usr <> Nothing AndAlso usr.Status = Constants.appAdmin Then
				tblAdminLinks.Visible = True

				' add table header
				Dim controls As New ArrayList()

				Dim lblAdminLinks As New Label()
				lblAdminLinks.Text = Me.GetPageConstText(htPageConstants, "CONST_AdminLinks_TEXT")
				controls.Add(lblAdminLinks)
				addTableRow("notes", controls)

				' add special settings link
				controls = New ArrayList()
				Dim hlSpecialSettings As New HyperLink()
				hlSpecialSettings.Text = Constants.AL_CHANGE_SPECIAL_SETTINGS.Replace("{member}", member.Name)
				hlSpecialSettings.NavigateUrl = "../" + Constants.SPECIAL_SETTINGS + "?" + Constants.SPECIAL_SETTINGS_USER_PARAM + "=" + member.ID
				controls.Add(hlSpecialSettings)
				addTableRow("notes_td_transparent", controls)
			End If

			' init friends count

			If usr <> Nothing Then
				Dim ufList As UsersFriends = usr.DirectFriends
				Dim mfList As UsersFriends = member.DirectFriends
				sfriendsCount = mfList.Count.ToString()
				Dim sUserfriendsCount As String = ufList.Count.ToString()

				If Convert.ToInt32(sfriendsCount) = 0 Then
					lblNoFriends.Visible = True
				End If

				If usr.ID = member.ID Then
					lblFriendshipPath.Text = (Me.GetPageConstText(htPageConstants, "CONST_Welcome_TEXT")).Replace("[PARAM]", member.Name)
					lblFriendshipPath.Visible = True
ElseIf ufList.Contains(member.ID) Then
					lblFriendshipPath.Text = (Me.GetPageConstText(htPageConstants, "CONST_MsgPathFriend_TEXT")).Replace("[PARAM]", member.Name)
					lblFriendshipPath.Visible = True
				Else
					' init friendship path
					Dim networkPath As String = ""

					' First find the NetworkFriend (if any) that corresponds to the member being browsed
					'
					' NOTE: THIS IS A VERY HEAVY OPERATION. In any case consider NOT working this way,
					' As an example a more elegant and system-load friendly design would be
					' to let the user explicitly request path computation.
					' This is DEPTH search in potentially LOTS of data - this will drain the app server
					' memory and the DB CPU.
					'
					Dim networkedMember As NetworkFriend = Nothing
					Dim networkHash As Hashtable = BO.Users.FindHashNetworkedUsers(usr.ID, Constants.NETWORK_MAX_DEPTH, True)
					If networkHash.Contains(member.ID) Then
						networkedMember = DirectCast(networkHash(member.ID), NetworkFriend)
					End If

					' If the network friend was found it should have the path
					If networkedMember <> Nothing Then
						' The path is a list of NetworkFriend objects,
						' ordered by distance (first is the closest)
						' NOTE: if when calling FindHashNetworkedUsers, the parameter for
						' direct friends is false the first direct friend won't be here!
						Dim netPath As ArrayList = networkedMember.Path
						For Each netFriendIDInPath As Integer In netPath
							Dim netFriend As BO.User = Users.GetUserByID(netFriendIDInPath)
							networkPath += "&gt;&lt; " + "<a href='" + Constants.MEMBERS + "?id=" + netFriend.ID + "'>" + netFriend.Name + "</a>" + " "
						Next
							' remove the first "&gt; "
						networkPath = networkPath.Substring(8)
					End If
					' Set the lable to the composed network path
					If Not ufList.Contains(member.ID) AndAlso networkPath.Length > 0 Then
						lblFriendshipPath.Text = "<font class=member_white_arrow>" + usr.Name + " &lt;</font>" + networkPath + "<font class=member_white_arrow>&gt</font> " + "<a href='" + Constants.MEMBERS + "?id=" + member.ID + "'>" + member.Name + "</a>"
						lblFriendshipPath.Visible = True
					End If
				End If
			Else
				lblFriendshipPath.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgLogin_TEXT")
			End If

			' init user details table

			' set age
			Dim lblAgeValue As New Label()
			Dim lblAge As New Label()
			lblAge.Text = Me.GetPageConstText(htPageConstants, "CONST_Age_TEXT")
			lblAge.Font.Bold = True
			Dim age As TimeSpan = DateTime.Today - member.BirthDay
			Dim ageYears As Double = (age.Days / 365)
			lblAgeValue.Text = (Convert.ToInt32(ageYears)).ToString()
			addTableRow(lblAge, lblAgeValue)

			'set gender
			Dim lblGenderValue As New Label()
			Dim lblGender As New Label()
			lblGender.Text = Me.GetPageConstText(htPageConstants, "CONST_Gender_TEXT")
			lblGender.Font.Bold = True
			Dim gender As Integer = member.Gender
			If gender = 1 Then
				lblGenderValue.Text = Me.GetPageConstText(htPageConstants, "CONST_Male_TEXT")
			End If
			If gender = 2 Then
				lblGenderValue.Text = Me.GetPageConstText(htPageConstants, "CONST_Female_TEXT")
			End If
			addTableRow(lblGender, lblGenderValue)

			'set status
			Dim lblStatusValue As New Label()
			Dim lblStatus As New Label()
			lblStatus.Text = Me.GetPageConstText(htPageConstants, "CONST_Status_TEXT")
			lblStatus.Font.Bold = True
			If member.MaritalStatus <> -1 Then
				lblStatusValue.Text = Constants.ARR_STATUS(member.MaritalStatus)
			Else
				lblStatusValue.Text = ""
			End If

			addTableRow(lblStatus, lblStatusValue)

			' set Country
			Dim lblCountryValue As New Label()
			Dim lblCountry As New Label()
			lblCountry.Text = Me.GetPageConstText(htPageConstants, "CONST_Country_TEXT")
			lblCountry.Font.Bold = True
			If member.CountryID = -1 Then
				lblCountryValue.Text = ""
			Else
				lblCountryValue.Text = "<a href='" + Constants.BROWSE + "?" + Constants.COUNTRY_PARAM + "=" + member.CountryID + "'>" + Constants.COUNTRIES.GetCountryByID(member.CountryID).Name + "</a>"
			End If

			addTableRow(lblCountry, lblCountryValue)

			'set City
			Dim lblCity As New Label()
			Dim lblCityValue As New Label()
			lblCity.Text = Me.GetPageConstText(htPageConstants, "CONST_City_TEXT")
			lblCity.Font.Bold = True
			If member.City <> Nothing Then
				If isHTML(member.City) Then
					lblCityValue.Text = member.City
				Else
					lblCityValue.Text = "<a href='" + Constants.BROWSE + "?" + Constants.CITY_PARAM + "=" + member.City + "'>" + member.City + "</a>"
				End If
			End If

			addTableRow(lblCity, lblCityValue)

			'set Place of Birth
			Dim lblPlaceOfBirthValue As New Label()
			Dim lblPlaceOfBirth As New Label()
			lblPlaceOfBirth.Text = Me.GetPageConstText(htPageConstants, "CONST_PlaceOfBirth_TEXT")
			lblPlaceOfBirth.Font.Bold = True
			If member.PlaceOfBirth <> Nothing Then
				If isHTML(member.PlaceOfBirth) Then
					lblPlaceOfBirthValue.Text = member.PlaceOfBirth
				Else
					lblPlaceOfBirthValue.Text = "<a href='" + Constants.BROWSE + "?" + Constants.CITY_PARAM + "=" + member.PlaceOfBirth + "'>" + member.PlaceOfBirth + "</a>"
				End If
			Else
				lblPlaceOfBirthValue.Text = "&nbsp;"
			End If

			addTableRow(lblPlaceOfBirth, lblPlaceOfBirthValue)

			' set Interests
			Dim lblInterestsValue As New Label()
			Dim lblInterests As New Label()
			lblInterests.Text = Me.GetPageConstText(htPageConstants, "CONST_Interests_TEXT")
			lblInterests.Font.Bold = True
			If member.Interests <> Nothing Then
				If isHTML(member.Interests) Then
					lblInterestsValue.Text = member.Interests
				Else
					Dim arrInterests As String() = member.Interests.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrInterests.Length
						lblInterestsValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.INTEREST_PARAM + "=" + arrInterests(i) + "'>" + arrInterests(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblInterestsValue.Text = lblInterestsValue.Text.Substring(0, lblInterestsValue.Text.Length - 2)
				End If
			Else
				lblInterestsValue.Text = "&nbsp;"
			End If


			addTableRow(lblInterests, lblInterestsValue)

			'set Occupation	
			Dim lblOccupationValue As New Label()
			Dim lblOccupation As New Label()
			lblOccupation.Text = Me.GetPageConstText(htPageConstants, "CONST_Occupation_TEXT")
			lblOccupation.Font.Bold = True
			If member.Occupation <> Nothing Then
				If isHTML(member.Occupation) Then
					lblOccupationValue.Text = member.Occupation
				Else
					lblOccupationValue.Text = "<a href='" + Constants.SEARCH + "?" + Constants.OCCUPATION_PARAM + "=" + member.Occupation + "'>" + member.Occupation + "</a>"
				End If
			Else
				lblOccupationValue.Text = "&nbsp;"
			End If

			addTableRow(lblOccupation, lblOccupationValue)

			If member.Affiliations <> "" AndAlso member.Affiliations <> Nothing Then
				Dim lblAffiliationsValue As New Label()
				Dim lblAffiliations As New Label()
				lblAffiliations.Text = Me.GetPageConstText(htPageConstants, "CONST_Affiliations_TEXT")
				lblAffiliations.Font.Bold = True

				If isHTML(member.Affiliations) Then
					lblAffiliationsValue.Text = member.Affiliations
				Else
					Dim arrAffiliations As String() = member.Affiliations.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrAffiliations.Length
						lblAffiliationsValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.AFFILIATIONS_PARAM + "=" + arrAffiliations(i) + "'>" + arrAffiliations(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblAffiliationsValue.Text = lblAffiliationsValue.Text.Substring(0, lblAffiliationsValue.Text.Length - 2)
				End If
				addTableRow(lblAffiliations, lblAffiliationsValue)
			End If

			If member.Companies <> "" AndAlso member.Companies <> Nothing Then
				Dim lblCompanies As New Label()
				Dim lblCompaniesValue As New Label()
				lblCompanies.Text = Me.GetPageConstText(htPageConstants, "CONST_Companies_TEXT")
				lblCompanies.Font.Bold = True

				If isHTML(member.Companies) Then
					lblCompaniesValue.Text = member.Companies
				Else
					Dim arrCompanies As String() = member.Companies.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrCompanies.Length
						lblCompaniesValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.COMPANIES_PARAM + "=" + arrCompanies(i) + "'>" + arrCompanies(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblCompaniesValue.Text = lblCompaniesValue.Text.Substring(0, lblCompaniesValue.Text.Length - 2)
				End If
				addTableRow(lblCompanies, lblCompaniesValue)
			End If

			If member.Schools <> "" AndAlso member.Schools <> Nothing Then
				Dim lblSchools As New Label()
				Dim lblSchoolsValue As New Label()
				lblSchools.Text = Me.GetPageConstText(htPageConstants, "CONST_Schools_TEXT")
				lblSchools.Font.Bold = True

				If isHTML(member.Schools) Then
					lblSchoolsValue.Text = member.Schools
				Else
					Dim arrSchools As String() = member.Schools.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrSchools.Length
						lblSchoolsValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.SCHOOLS_PARAM + "=" + arrSchools(i) + "'>" + arrSchools(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblSchoolsValue.Text = lblSchoolsValue.Text.Substring(0, lblSchoolsValue.Text.Length - 2)
				End If

				addTableRow(lblSchools, lblSchoolsValue)
			End If

			If member.ImageURL <> "" AndAlso member.ImageURL <> Nothing Then
				Dim lblFavImage As New Label()
				Dim hlFavImageURL As New HyperLink()
				lblFavImage.Text = Me.GetPageConstText(htPageConstants, "CONST_SeeImage_TEXT")
				lblFavImage.Font.Bold = True

				'hlFavImageURL.NavigateUrl = member.ImageURL;
				'hlFavImageURL.Text = member.ImageURL;
				If member.ImageURLName <> Nothing AndAlso member.ImageURLName <> "" Then
					hlFavImageURL.Text = member.ImageURLName
				End If

				'hlFavImageURL.Target = "_blank";
				hlFavImageURL.Attributes.Add("href", "#")
				hlFavImageURL.Attributes.Add("onclick", Me.constructImageURL(member.ImageURL))

				addTableRow(lblFavImage, hlFavImageURL)
			End If

			If member.Music <> "" AndAlso member.Music <> Nothing Then
				Dim lblFavMusic As New Label()
				Dim lblFavMusicValue As New Label()
				lblFavMusic.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteMusic_TEXT")
				lblFavMusic.Font.Bold = True

				If isHTML(member.Music) Then
					lblFavMusicValue.Text = member.Music
				Else
					Dim arrMusic As String() = member.Music.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrMusic.Length
						lblFavMusicValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.MUSIC_PARAM + "=" + arrMusic(i) + "'>" + arrMusic(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavMusicValue.Text = lblFavMusicValue.Text.Substring(0, lblFavMusicValue.Text.Length - 2)
				End If

				addTableRow(lblFavMusic, lblFavMusicValue)
			End If

			If member.Books <> "" AndAlso member.Books <> Nothing Then
				Dim lblFavBooks As New Label()
				Dim lblFavBooksValue As New Label()
				lblFavBooks.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteBooks_TEXT")
				lblFavBooks.Font.Bold = True

				If isHTML(member.Books) Then
					lblFavBooksValue.Text = member.Books
				Else
					Dim arrBooks As String() = member.Books.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrBooks.Length
						lblFavBooksValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.BOOKS_PARAM + "=" + arrBooks(i) + "'>" + arrBooks(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavBooksValue.Text = lblFavBooksValue.Text.Substring(0, lblFavBooksValue.Text.Length - 2)
				End If
				addTableRow(lblFavBooks, lblFavBooksValue)
			End If

			If member.TV <> "" AndAlso member.TV <> Nothing Then
				Dim lblFavTV As New Label()
				Dim lblFavTVValue As New Label()
				lblFavTV.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteTVShows_TEXT")
				lblFavTV.Font.Bold = True

				If isHTML(member.TV) Then
					lblFavTVValue.Text = member.TV
				Else
					Dim arrTVs As String() = member.TV.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrTVs.Length
						lblFavTVValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.TV_PARAM + "=" + arrTVs(i) + "'>" + arrTVs(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavTVValue.Text = lblFavTVValue.Text.Substring(0, lblFavTVValue.Text.Length - 2)
				End If

				addTableRow(lblFavTV, lblFavTVValue)
			End If

			If member.Movies <> "" AndAlso member.Movies <> Nothing Then
				Dim lblFavMovies As New Label()
				Dim lblFavMoviesValue As New Label()
				lblFavMovies.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteMovies_TEXT")
				lblFavMovies.Font.Bold = True

				If isHTML(member.Movies) Then
					lblFavMoviesValue.Text = member.Movies
				Else
					Dim arrMovies As String() = member.Movies.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrMovies.Length
						lblFavMoviesValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.MOVIES_PARAM + "=" + arrMovies(i) + "'>" + arrMovies(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavMoviesValue.Text = lblFavMoviesValue.Text.Substring(0, lblFavMoviesValue.Text.Length - 2)
				End If

				addTableRow(lblFavMovies, lblFavMoviesValue)
			End If

			' Bind data
			If Not IsPostBack Then
				Dim memList As UsersFriends = member.DirectFriends
				If memList.Count <> 0 Then
					BindList()
				End If
				BindGrid(dgMessages, "comments")
				BindGrid(dgBlog, "blog")
			End If
			If usr <> Nothing AndAlso usr.ID.Equals(id) Then
				hlAddComment2.Visible = False
				hlAddComment3.Visible = False
				lblCommentsLine.Visible = False
				lblLine.Visible = False
			End If

			hlViewMoreComments.NavigateUrl = "../" + Constants.FRIENDS_COMMENTS_PAGE + "?usr=" + id + "&action=1"
			hlViewAllComments.NavigateUrl = "../" + Constants.FRIENDS_COMMENTS_PAGE + "?usr=" + id + "&action=1"

			Dim commentsCountToCompare As Integer = member.Comments.Count
			If LoggedUser <> Nothing AndAlso member.ID = LoggedUser.ID Then
				commentsCountToCompare += member.NewComments.Count
			End If

			If commentsCountToCompare > 0 Then
				If commentsCountToCompare <= Constants.COMMENTS_ON_PROFILE_PAGE Then
					lblNumComments.Text = String.Format(" Listing 1-{0} of {1} comments", commentsCountToCompare, commentsCountToCompare)
				Else
					lblNumComments.Text = String.Format(" Listing 1-{0} of {1} comments", Constants.COMMENTS_ON_PROFILE_PAGE, commentsCountToCompare)
				End If
			End If

			If commentsCountToCompare <= Constants.COMMENTS_ON_PROFILE_PAGE Then
				hlViewMoreComments.Visible = False
				lblLine.Visible = False
				hlViewAllComments.Visible = False
				lblCommentsLine.Visible = False
			End If

			Dim memberGroups As ArrayList = Groups.MyGroups(member.ID, Constants.GROUP_SORT_BY_MOST_RECENT)
			For Each grp As BO.Group In memberGroups
				lblGroup.Text += "<a href='" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID + "'>" + grp.Name + "</a>" + ", "
			Next

			If memberGroups.Count > 0 Then
				lblGroup.Text = lblGroup.Text.Substring(0, lblGroup.Text.Length - 2)
			Else
				tblGroups.Visible = False
			End If
		End Sub

		' add row to details table
		Private Sub addTableRow(ByVal ctlName As Control, ByVal ctlValue As Control)
			Dim tr As New TableRow()
			Dim td1 As New TableCell()
			Dim td2 As New TableCell()

			td1.Controls.Add(ctlName)
			td2.Controls.Add(ctlValue)
			td1.Width = 100
			td2.Width = 210
			td1.CssClass = "member_main_text"
			td2.CssClass = "member_main_text"
			tr.Cells.Add(td1)
			tr.Cells.Add(td2)

			tblUserDetails.Rows.Add(tr)
		End Sub

		' add Row to Admin links table
		Private Sub addTableRow(ByVal cssclass As String, ByVal ctls As ArrayList)
			Dim tr As New TableRow()
			Dim td As New TableCell()
			td.CssClass = cssclass
			For Each ctl As Control In ctls
				td.Controls.Add(ctl)
			Next
			tr.Cells.Add(td)
			tblAdminLinks.Rows.Add(tr)
		End Sub

		'		public ICollection CreateDataSource() 
		Public Overloads Overrides Function CreateDataSource() As ICollection
			Dim usr As BO.User = Users.GetUserByID(id)
			Dim i As Integer
			Dim dt As New DataTable()
			Dim dr As DataRow

			dt.Columns.Add(New DataColumn("ImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Name", GetType(String)))
			dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
			dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
			dt.Columns.Add(New DataColumn("FriendItemURL", GetType(String)))
			dt.Columns.Add(New DataColumn("FullName", GetType(String)))

			Dim tmpUserPic As UserPicture = Nothing

			Dim ufList As UsersFriends = usr.DirectFriends
			Dim usrDFWithMazFirst As New ArrayList()
			Dim FriendsCount As Integer = ufList.Count
			Dim imagesOnLastRow As Integer = 0

			Dim itemCount As Integer = Math.Min(Constants.MAX_PICTURES_ON_WELCOME_PAGE, FriendsCount)
			Math.DivRem(itemCount, Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE, imagesOnLastRow)

			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			' maz's user to be the first
			Dim usrMaz As User = Users.GetUserByEmail(Constants.WELCOME_MESSAGE_SENDER)
			'			bool bMaz = false;
			'			if( ufList.Contains(usrMaz.ID) )
			'			{	
			'				dr = dt.NewRow();
			'
			'				tmpUserPic = usrMaz.DefaultPicture;
			'				if(tmpUserPic != null)
			'				{
			'					dr[0] = Pictures.GetPictureSrcFullURL( tmpUserPic, true, "../" );
			'				}
			'				else
			'				{
			'					dr[0] = "../images/default_thumbnail.gif";
			'				}
			'				dr[1] = getBeginning( HttpUtility.HtmlEncode( usrMaz.Name ), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE);
			'				if(LoggedUsersList.Contains(usrMaz.ID))
			'					dr[2] = "../images/online_status.gif"; // init according to the friend's online status
			'				else
			'					dr[2] = "../images/spacer.gif"; 
			'				dr[3] = usrMaz.ID;
			'				dr[4] = "../" + Constants.MEMBERS + "?id=" + usrMaz.ID;
			'
			'				dt.Rows.Add(dr);
			'				
			'				if( itemCount == Constants.MAX_PICTURES_ON_WELCOME_PAGE )
			'				{
			'					bMaz = true;
			'					itemCount--;
			'				}
			'			}

			Dim mazFound As Boolean = False
			For Each udf As DirectFriend In ufList
				If udf.[Friend].ID = usrMaz.ID Then
					usrDFWithMazFirst.Insert(0, udf)
					mazFound = True
				Else
					usrDFWithMazFirst.Add(udf)
				End If
			Next
			If mazFound Then
				If usrDFWithMazFirst.Count > 1 Then
					usrDFWithMazFirst.Sort(1, usrDFWithMazFirst.Count - 1, New BO.GenericSort("DateAdded", "DESC"))
				End If
			Else
				usrDFWithMazFirst.Sort(New BO.GenericSort("DateAdded", "DESC"))
			End If

			Dim idx As Integer = 0
			While idx < itemCount
				'				DirectFriend df = (DirectFriend) ufList.GetList()[ idx ];
				'
				'				// maz's user to be the first
				'				if(df.Friend.ID == usrMaz.ID)
				'				{
				'					if( (itemCount < Constants.MAX_PICTURES_ON_WELCOME_PAGE ) && bMaz )
				'						itemCount++;
				'					continue;
				'				}

				Dim df As DirectFriend = DirectCast(usrDFWithMazFirst(idx), DirectFriend)

				dr = dt.NewRow()

				tmpUserPic = df.[Friend].DefaultPicture
				If tmpUserPic <> Nothing Then
					dr(0) = Pictures.GetPictureSrcFullURL(tmpUserPic, True, "../")
				Else
					dr(0) = "../images/default_thumbnail.gif"
				End If
				dr(1) = getBeginning(HttpUtility.HtmlEncode(df.[Friend].Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
				If LoggedUsersList.Contains(df.[Friend].ID) Then
					dr(2) = "../images/online_status.gif"
				Else
					dr(2) = "../images/spacer.gif"
					' init according to the friend's online status
				End If
				dr(3) = df.[Friend].ID
				dr(4) = "../" + Constants.MEMBERS + "?id=" + df.[Friend].ID
				dr(5) = df.[Friend].Name

				dt.Rows.Add(dr)
				System.Math.Max(System.Threading.Interlocked.Increment(idx),idx - 1)
			End While

			If imagesOnLastRow <> 0 Then
				blankImagesCount = Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE - imagesOnLastRow
				i = imagesOnLastRow
				While i < Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE
					dr = dt.NewRow()
					'dr[0] = "../images/empty_image.gif";
					dr(0) = "../images/spacer.gif"
					dr(1) = ""
					dr(2) = "../images/spacer.gif"
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If

			Dim dv As New DataView(dt)
			Return dv
		End Function

		'		public void BindList() 
		Public Overloads Overrides Sub BindList()
			dlAllFriends.DataSource = CreateDataSource()
			dlAllFriends.DataBind()

			Dim itemsCount As Integer = dlAllFriends.Items.Count
			Dim blankImageIndex As Integer = itemsCount - blankImagesCount
			Dim i As Integer = 0
			i = blankImageIndex
			While i < itemsCount
				(DirectCast(dlAllFriends.Items(i).FindControl("hlName"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
				(DirectCast(dlAllFriends.Items(i).FindControl("hlPhoto"), System.Web.UI.WebControls.HyperLink)).CssClass = "empty_image"
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While
		End Sub

		Protected Function CreateDataSourceForGrid(ByVal type As String) As ICollection
			Dim usr As BO.User = Users.GetUserByID(id)

			Dim msgList As New ArrayList()
			Dim commentsList As New ArrayList()
			Dim dt As New DataTable()
			Dim startIndex As Integer = -1
			Dim endIndex As Integer = -1
			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			' List user's inbox messages
			Select Case type
				Case "comments"
					commentsList = usr.Comments
					startIndex = 0
					endIndex = startIndex + Constants.COMMENTS_ON_PROFILE_PAGE
					endIndex = Math.Min(usr.Comments.Count, endIndex)
					'endIndex = startIndex + commentsList.Count;	

					dt.Columns.Add(New DataColumn("SenderID", GetType(Integer)))
					dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
					dt.Columns.Add(New DataColumn("SenderImageURL", GetType(String)))
					dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
					dt.Columns.Add(New DataColumn("MemberURL", GetType(String)))
					dt.Columns.Add(New DataColumn("Date", GetType(String)))
					dt.Columns.Add(New DataColumn("Time", GetType(String)))
					dt.Columns.Add(New DataColumn("Comment", GetType(String)))
					dt.Columns.Add(New DataColumn("CommentID", GetType(String)))
					dt.Columns.Add(New DataColumn("ButtonsVisibility", GetType(Boolean)))
					dt.Columns.Add(New DataColumn("RejectText", GetType(String)))
					dt.Columns.Add(New DataColumn("SenderNameFull", GetType(String)))
					dt.Columns.Add(New DataColumn("FooterSpaceVisibility", GetType(Boolean)))
					Exit Select
				Case "blog"
					startIndex = 0
					endIndex = startIndex + Constants.MAX_MESSAGES_ON_MEMBERS_PAGE

					dt.Columns.Add(New DataColumn("MessageID", GetType(Integer)))
					dt.Columns.Add(New DataColumn("Date", GetType(String)))
					dt.Columns.Add(New DataColumn("URL", GetType(String)))
					dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
					dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
					dt.Columns.Add(New DataColumn("Subject", GetType(String)))
					dt.Columns.Add(New DataColumn("ViewMsgURL", GetType(String)))

					msgList = Messages.GetUserBlogs(usr.ID)
					Exit Select
			End Select

			If msgList.Count = 0 AndAlso type = "blog" Then
				dgBlog.Visible = False
				hlAllBlog.Visible = False
				lblEmptyBlog.Visible = True
ElseIf commentsList.Count = 0 AndAlso type = "comments" Then
				dgMessages.Visible = False
				lblNoComments.Visible = True
			Else
				Dim curMessageDate As DateTime, curCommentDate As DateTime
				Dim dr As DataRow
				Dim temp As UserPicture
				Dim curSender As User
				Dim usrComment As UserComment

				' List user's inbox messages
				Dim i As Integer = startIndex
				While i < endIndex
					dr = dt.NewRow()

					Select Case type
						Case "comments"
							endIndex = Math.Min(endIndex, commentsList.Count)
							dr = dt.NewRow()
							usrComment = DirectCast(commentsList(i), UserComment)
							curCommentDate = usrComment.[Date]
							curSender = Users.GetUserByID(usrComment.PostedByUserID)

							dr(0) = usrComment.PostedByUserID
							dr(1) = getBeginning(HttpUtility.HtmlEncode(curSender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(11) = curSender.Name
							temp = curSender.DefaultPicture
							If temp <> Nothing Then
								dr(2) = Pictures.GetPictureSrcFullURL(temp, True, "../")
							Else
								dr(2) = Constants.DEFAULT_THUMBNAIL_IMAGE_URL
							End If
							If LoggedUsersList.Contains(curSender.ID) Then
								dr(3) = "../images/online_status.gif"
							Else
								dr(3) = "../images/spacer.gif"
							End If
							dr(4) = "../" + Constants.MEMBERS + "?id=" + usrComment.PostedByUserID
							dr(5) = curCommentDate.DayOfWeek + ", " + Constants.MONTHS(curCommentDate.Month - 1) + " " + curCommentDate.Day + ", " + curCommentDate.Year
							dr(6) = curCommentDate.ToShortTimeString()
							dr(7) = usrComment.Comment
							'usrComment.Comment.Replace(Environment.NewLine, "<br>") ;
							dr(8) = usrComment.ID

							If LoggedUser <> Nothing Then
								If (usrComment.CommentStatus = UserComment.Status.ucsNew) AndAlso (Not LoggedUser.ApproveComments) Then
									dr(9) = True
									dr(10) = "Reject"
									dr(12) = True
								Else
									dr(9) = False
									If id = LoggedUser.ID OrElse LoggedUser.ID = usrComment.PostedByUserID Then
										dr(10) = "Remove"
										dr(12) = True
									Else
										dr(10) = ""
										dr(12) = False
									End If
								End If
							Else
								dr(9) = False
								dr(10) = ""
								dr(12) = False
							End If
							Exit Select
						Case "blog"
							endIndex = Math.Min(endIndex, msgList.Count)
							Dim blog As Blog = DirectCast(msgList(i), Blog)
							curMessageDate = blog.DateSent
							dr(0) = blog.ID
							dr(1) = Constants.ARR_MONTHS(curMessageDate.Month - 1) + " " + curMessageDate.Day + "<br />" + curMessageDate.ToShortTimeString()
							dr(2) = "../" + Constants.MEMBERS + "?id=" + blog.SenderID.ToString()
							dr(3) = blog.SenderID.ToString()
							dr(4) = getBeginning(HttpUtility.HtmlEncode(blog.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
							dr(5) = Server.HtmlEncode(blog.Subject)
							dr(6) = "../" + Constants.VIEW_MEMBER_BLOG_COMMENTS + "?id=" + blog.ID + "&usr=" + usr.ID
							Exit Select
					End Select
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If
			Dim dv As New DataView(dt)
			Return dv
		End Function

		Protected Sub BindGrid(ByVal gridName As DataGrid, ByVal type As String)
			'init datagrid with database data ordered by "orederBy" param
			gridName.DataSource = CreateDataSourceForGrid(type)
			gridName.DataBind()
		End Sub
		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dlAllFriends.ItemCommand, AddressOf Me.dlAllFriends_ItemCommand
			AddHandler Me.dgMessages.ItemCommand, AddressOf Me.dgMessages_ItemCommand

		End Sub
#End Region

		Private Sub dlAllFriends_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
			Dim src As Object = e.CommandSource
			Dim srcType As String = src.[GetType]().ToString()
			Dim cmd As String = e.CommandName
			Dim arg As String = ""
			If srcType.Equals("System.Web.UI.WebControls.ImageButton") Then
				arg = (DirectCast(src, ImageButton)).CommandArgument
			Else
				arg = (DirectCast(src, LinkButton)).CommandArgument
			End If
			Select Case cmd
				Case "MemberRedirect"
					Response.Redirect(Constants.MEMBERS + "?id=" + e.CommandArgument)
					Exit Select
			End Select
		End Sub

		Private Sub dgMessages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
			Dim lbPushed As LinkButton = DirectCast(e.CommandSource, LinkButton)
			Dim cmd As String = e.CommandName
			Select Case cmd
				Case "Reject"
					' reject/remove comment
					member.RemoveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
				Case "Approve"
					'approve comment
					member.ApproveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
			End Select
			Response.Redirect(Constants.MEMBERS + "?id=" + id)
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		'    public System.Web.UI.HtmlControls.HtmlForm Form1 {
		Public Overloads Overrides ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace






